let isBaseUrl = false; //false为测试域名 true为正式域名 
let BASE_URL = isBaseUrl ? 'http://znkj.jibeimall.com/app' : 'http://znkj.jibeimall.com/app';
// easycolor..juxingqiansheng.com
// jbtest..juxingqiansheng.com  http://jbtest.juxingqiansheng.com

const myRequest = (options) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: (options.baseUrl || BASE_URL) + options.url,
      method: options.method || 'GET',
      data: options.data || {},
      header: options.header || {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      // header: options.header || {'Content-Type':'application/json'},
      success: (res) => {
        if (res.statusCode !== 200) {
          return uni.showToast({
            title: res.errMsg,
            icon: 'none',
            duration: 3000
          })
        }
        resolve(res)
      },
      fail: (err) => {
        uni.showToast({
          title: '请求接口失败',
          icon: "loading"
        })
        reject(err);
		uni.hideLoading();
      }
    })
  })
}

const showToast = (title, icon = 'success', duration = 1500) => {
  return uni.showToast({
    title,
    icon,
    duration,
  });
}

module.exports = {
  myRequest,
  showToast,
  BASE_URL
}
